// 封装读取文件操作
const fs = require("fs");
const { promisify } = require("util");
const path = require("path");

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

const dbPath =(url) => path.join(__dirname, url);
// const dbPath = path.join(__dirname, "../mock/project.json");

exports.getDb = async (url) => {
  const data = await readFile(dbPath(url), "utf8");
  return JSON.parse(data);
};

exports.saveDb = async (db,url) => {
  const data = JSON.stringify(db, null, "  ");
  await writeFile(dbPath(url),data);
};